Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up IsRegularPGroup #5797

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

fingolfin
Copy link
Member

@fingolfin fingolfin commented Sep 16, 2024

The speed up is achieved by carefully caching some more
intermediate results. Also avoid an Agemo call, and drop a size
check that I thought was beneficial, but in benchmarking harder
examples turned out to be not helpful.

Some timeing on my M1 MacBook Pro. Before this patch:

gap> IsRegularPGroup(DirectProduct(SmallGroup(3^5,22),SmallGroup(3^5,22)));; time;
27609
gap> IsRegularPGroup(DirectProduct(SmallGroup(3^5,22),SmallGroup(3^5,39)));; time;
77479

After this patch:

gap> IsRegularPGroup(DirectProduct(SmallGroup(3^5,22),SmallGroup(3^5,22)));; time;
1488
gap> IsRegularPGroup(DirectProduct(SmallGroup(3^5,22),SmallGroup(3^5,39)));; time;
3957

Also fix some references to Huppert's book.

@fingolfin fingolfin added topic: performance bugs or enhancements related to performance (improvements or regressions) topic: library release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes labels Sep 16, 2024
@fingolfin fingolfin force-pushed the mh/tune-IsPowerfulPGroup branch 2 times, most recently from 833ef66 to aba3e9d Compare September 24, 2024 20:15
@fingolfin
Copy link
Member Author

@jackschmidt perhaps you'd be willing to give this patch a glance over?

@fingolfin fingolfin changed the title Speed up IsPowerfulPGroup Speed up IsRegularPGroup Sep 26, 2024
Copy link
Contributor

@jackschmidt jackschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! These changes look good to me. I have not had a chance to time check them, or to try to find pathological examples, but the only line that potentially adds more work is the IsOne(g*h), and I hope that is negligible compared to everything else. All other changes should strictly reduce the amount of work done if the slow path is taken (and don't do anything if one of the earlier quick checks applies).


if not IsPGroup(G) then
return false;
fi;

p:=PrimePGroup(G);
if p = 2 then
# see [Hup67, Satz 10.3 a)]
# see [Hup67, Satz III.10.3 a)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. The previous citation was incomplete. This is correct

# we just check the direct definition, with a minor twist to avoid
# calling Agemo
g := ap_bp / ab_p;
h := Comm(a,b)^p;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. All the caching is correct and should avoid repeated element calculations

# calling Agemo
g := ap_bp / ab_p;
h := Comm(a,b)^p;
if g = h or IsOne(g*h) then continue; fi;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. This new check is most advantageous for small p, but should always be cheap (g=h always cheap, g*h should not be expensive). For small p, I suspect it completely avoids the subgroup check in many cases

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very, very much for you feedback @jackschmidt and sorry for taking so long to get back to you.

Regarding this point, indeed g=h is fast and indeed for small $p$ the cost for checking IsOne(g*h) is absolutely worth it, based on extensive tests with groups of order $3^{10}$ formed as direct products of smaller $3$-groups.

lib/grp.gi Outdated
H := DerivedSubgroup(H);
if not (ap_bp / ab_p) in Agemo(H, p) then
H := NormalClosure(H, [h]); # faster than Agemo(DerivedSubgroup(H), p);
if not g in H then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. This new H should be much faster to compute, and if g is not in H, then G is surely not regular, but if G is regular, then this H is the same as the more expensive Agemo subgroup, and the check will always pass.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now added a comment explaining what's going on, I hope this makes it much clearer. Apologies for not doing that before, I really should have :-(

The speed up is achieved by carefully caching some more
intermediate results. Also avoid an Agemo call, and drop a size
check that I thought was beneficial, but in benchmarking harder
examples turned out to be not helpful.

Some timeing on my M1 MacBook Pro. Before this patch:

    gap> IsRegularPGroup(DirectProduct(SmallGroup(3^5,22),SmallGroup(3^5,22)));; time;
    27609
    gap> IsRegularPGroup(DirectProduct(SmallGroup(3^5,22),SmallGroup(3^5,39)));; time;
    77479

After this patch:

    gap> IsRegularPGroup(DirectProduct(SmallGroup(3^5,22),SmallGroup(3^5,22)));; time;
    1488
    gap> IsRegularPGroup(DirectProduct(SmallGroup(3^5,22),SmallGroup(3^5,39)));; time;
    3957

Also fix some references to Huppert's book.
Copy link
Contributor

@jackschmidt jackschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! The revised changes continue to be correct and a strict improvement on the original, and the added documentation is much appreciated.

@fingolfin fingolfin merged commit 56b9f5e into gap-system:master Oct 9, 2024
33 checks passed
@fingolfin fingolfin deleted the mh/tune-IsPowerfulPGroup branch October 9, 2024 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes topic: library topic: performance bugs or enhancements related to performance (improvements or regressions)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants